package com.winsomely.leecode;

/**
 * 汉明距离
 * 
 * @author liujiawei
 *
 */
public class HammingDistance {

	public int hammingDistance(int x, int y) {
		String sx = Integer.toBinaryString(x);
		String sy = Integer.toBinaryString(y);
		int xi = sx.length() - 1;
		int yi = sy.length() - 1;
		int m = 0;
		while (xi >= 0 || yi >= 0) {
			char xc = '0';
			char yc = '0';
			if (xi >= 0) {
				xc = sx.charAt(xi);
			}
			if (yi >= 0) {
				yc = sy.charAt(yi);
			}
			if (xc != yc) {
				m++;
			}
			xi--;
			yi--;
		}
		return m;
	}

	public static void main(String[] args) {
		HammingDistance t = new HammingDistance();
		System.out.println(t.hammingDistance(60, 161456456));
	}

}
